package ntd.util.config.common.enums;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.EnumUtil;
import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.*;

/**
 * mysql 数据库类型映射枚举
 */
@AllArgsConstructor
public enum EnumDataRule implements BaseEnumInterface {

    RULE_EQ("等于"),
    RULE_NE("不等于"),
    RULE_NE_NULL("不为空"),
    RULE_MAX("最大值"),
    RULE_MIN("最小值"),
    RULE_GE("大于等于"),
    RULE_GT("大于"),
    RULE_LE("小于等于"),
    RULE_LT("小于"),
    ;

    @Getter
    private String name;

    @Override
    public String getValue() {
        return this.name();
    }

    public static EnumDataRule val(String dataRule) {
        return EnumUtil.getEnumMap(EnumDataRule.class).get(dataRule);
    }

    public static HashSet<EnumDataRule> maxOrMin() {
        return CollectionUtil.newHashSet(EnumDataRule.RULE_MAX, EnumDataRule.RULE_MIN);
    }

    public boolean compare(String str, String str2) {
        if (StrUtil.isBlank(str) || StrUtil.isBlank(str2)) {
            return false;
        }
        switch (this) {
            case RULE_NE: return !StrUtil.equals(str, str2);
            case RULE_EQ: return StrUtil.equals(str, str2);
            case RULE_LT: return StrUtil.compare(str, str2, false) < 0;
            case RULE_LE: return StrUtil.compare(str, str2, false) < 1;
            case RULE_GT: return StrUtil.compare(str, str2, false) > 0;
            case RULE_GE: return StrUtil.compare(str, str2, false) > -1;
            case RULE_NE_NULL: return StrUtil.isNotBlank(str);
        }
        return false;
    }

}
